package com.qxzn.app.personalcenter.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.qxzn.app.bean.LatestVersionBean;
import com.qxzn.app.page.BaseActivity;
import com.qxzn.app.page.interfaces.MyInterface;
import com.qxzn.app.page.model.UpdateVersionModel;
import com.qxzn.app.page.view.CustomItemView;
import com.qxzn.app.personalcenter.R;
import com.qxzn.app.personalcenter.R2;
import com.qxzn.app.util.AppUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class VersionUpdateActivity extends BaseActivity implements MyInterface.OnUpdateVersionListener {

    @BindView(R2.id.tv_version)
    TextView tvVersion;
    @BindView(R2.id.civ_update)
    CustomItemView civUpdate;
    private UpdateVersionModel model;

    @Override
    protected int initLayout() {
        return R.layout.activity_version_update;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void iniTitleBar() {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        model = new UpdateVersionModel(this, this);
        model.getUpdateVersionInfo(false);
        tvVersion.setText("Version " + AppUtil.getVersionName(this));
    }

    @OnClick(R2.id.civ_update)
    public void onViewClicked() {
        model.getUpdateVersionInfo(true);
    }

    @Override
    public void onGetUpdateInfoSuccess(LatestVersionBean.DataBean data) {
        civUpdate.getRightDotView().setVisibility(View.VISIBLE);
        civUpdate.setRightText("v_" + data.getNumber());
    }

    @Override
    public void onGetUpdateInfoFailure() {
        AppUtil.showToast(this, "网络有点问题，请稍后再试！");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        model.removeListener();
    }
}
